<template>
  <div style="overflow: hidden">
    <span style="display:none;position: absolute;">{{name}}</span>
    <div class="xj-component-left-sidenav">
      <ul>
        <span class="title-text">{{ $t("更新日志") }}</span>
        <span class="title-text">{{ $t("开发指南") }}</span>
        <li
          v-for="item in reduceList"
          :key="item.name"
          @click="changeActiveName(item.name)"
          @mouseover="hoverName = item.name"
          @mouseleave="hoverName = ''"
        >

          <a :class="isChangeColor(item.name)" :href="item.path">{{
            item.name
          }}</a>
        </li>
      </ul>
      <span class="title-text">{{ $t("组件") }}</span>
      <ul v-for="(item2, index2) in componentList">
        <span class="classify-text">{{ index2 }}</span>
        <li
          v-for="item in item2"
          :key="item.name"
          @click="changeActiveName(item.name)"
          @mouseover="hoverName = item.name"
          @mouseleave="hoverName = ''"
        >
          <a :class="isChangeColor(item.name)" :href="item.path">{{
            item.name
          }}</a>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRoute } from "vue-router";
import { ref, toRaw, watch } from "vue";
import EN from "@/lang/en.json";
const route = useRoute();
let hoverName = ref("");
type types = {
  name: string;
  path: string;
};
import bus from "@/utils/bus";
let name = ref("")
bus.on("forceUpdate", (e) => {
  name.value = name.value==""?"1":""
});
const emits = defineEmits(["toTop"]);
interface listInterface {
  reduceList: types[];
  componentList: any;
}

let props = defineProps<listInterface>();
let activeName = ref(initActiveName());

function changeActiveName(item: any) {
  activeName.value = item;
  emits("toTop");
}
function initActiveName() {
  let newString = "/#" + route.fullPath;
  let newArray = [
    ...toRaw(props.reduceList),
    ...toRaw(props.componentList?.Basice),
    ...toRaw(props.componentList.Form),
    ...toRaw(props.componentList.Data),
    ...toRaw(props.componentList.Notic),
    ...toRaw(props.componentList.Others),
  ];
  for (let i = 0; i < newArray.length; i++) {
    if (newString == newArray[i].path) {
      return newArray[i].name;
    }
  }
}
function isChangeColor(item: any) {
  if (item == activeName.value || item == hoverName.value || item == route.fullPath.substring(12) || EN[item] == route.fullPath.substring(12)) {
    return "active-color";
  }
}
watch(
  () => route.fullPath,
  () => {
    activeName.value = initActiveName();
  }
);
</script>
<style lang="scss" scoped>
.xj-component-left-sidenav {
  padding-top: 50px;
  padding-bottom: 40px;
  overflow: scroll;
  width: 240px;
  height: calc(100vh - 154px);
  bottom: 0;
  margin-right: -17px;
  .title-text {
    font-size: 16px;
    line-height: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    text-decoration: none;
    display: block;
    position: relative;
    transition: 0.15s ease-out;
    font-weight: 700;
  }
  ul {
    padding-bottom: 50px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    .classify-text {
      font-size: 12px;
      color: #999;
      line-height: 26px;
      margin-top: 8px;
      display: block;
    }
  }

  li {
    cursor: pointer;
    display: block;
    height: 45px;
    line-height: 45px;
    font-size: 14px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-weight: 500;
    a {
      position: relative;
      transition: 0.15s ease-out;
      margin: 0;
      padding: 0;
      text-decoration: none;
      display: block;
      height: 40px;
      line-height: 40px;
      font-size: 14px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      font-weight: 400;
    }
    .active-color {
      color: $primary;
    }
  }
}
</style>
